/*
 * @Title Server.java
 * @Copyright Copyright(c) 2018
 * @Description
 * 在当前工程target/classes目录下执行start rmiregistry
 * @Company com.lizhen
 * @author lizhen
 * @version 0.0.1
 */
package com.lizhen.rmi.server;

import com.lizhen.util.HelloRMI;
import com.lizhen.util.HelloRMIJavaFX;
import com.lizhen.util.HelloRMIPerson;
import com.lizhen.util.impl.HelloRMIImpl;
import com.lizhen.util.impl.HelloRMIJavaFXImpl;
import com.lizhen.util.impl.HelloRMIPersonImpl;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 * @author lizhen
 */
public class Server {

    /**
     * @author lizhen
     */
    public Server() {
    }

    /**
     * @author lizhen
     */
    public static void main(String[] args) {
//        HelloServer.main(null);
//        HelloServerJavaFX.main(null);
        HelloServerPerson.main(null);
    }

    static class HelloServer {
        public static void main(String[] args) {
            try {
                HelloRMIImpl obj = new HelloRMIImpl();
                HelloRMI stub = (HelloRMI) UnicastRemoteObject.exportObject(obj, 0);
                Registry registry = LocateRegistry.getRegistry();
                registry.bind("HelloRMI", stub);

                System.out.println("Server ready");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    static class HelloServerJavaFX extends HelloRMIJavaFXImpl {
        public HelloServerJavaFX() {
        }

        public static void main(String args[]) {
            try {
                HelloRMIJavaFXImpl obj = new HelloRMIJavaFXImpl();
                HelloRMIJavaFX stub = (HelloRMIJavaFX) UnicastRemoteObject.exportObject(obj, 0);
                Registry registry = LocateRegistry.getRegistry();
                registry.bind("HelloRMIJavaFX", stub);

                System.out.println("Server ready");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    static class HelloServerPerson extends HelloRMIPersonImpl {
        public HelloServerPerson() {
        }

        public static void main(String args[]) {
            try {
                HelloRMIPersonImpl obj = new HelloRMIPersonImpl();
                HelloRMIPerson stub = (HelloRMIPerson) UnicastRemoteObject.exportObject(obj, 0);
                Registry registry = LocateRegistry.getRegistry();
                registry.bind("HelloRMIPerson", stub);

                System.out.println("Server ready");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}